package org.smart.access.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.smart.access.model.House;
import org.smart.access.model.User;

import java.time.LocalDateTime;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class UserInfo {
    private Long uid;
    private String building;
    private String room;
    private String realname;
    private String phone;
    private Integer gender;
    private String residentNature;
    private String ownerName;
    private Integer role;
    private Integer status;
    private LocalDateTime createTime;
    private LocalDateTime updateTime;

    public static UserInfo of(User user, House house, String ownerName) {
        UserInfoBuilder builder = UserInfo.builder();
        if (null != user) {
            builder.uid(user.getUid())
                    .realname(user.getRealname())
                    .phone(user.getPhone())
                    .gender(user.getGender())
                    .residentNature(user.getResidentNature())
                    .role(user.getRole())
                    .status(user.getStatus())
                    .createTime(user.getCreateTime())
                    .updateTime(user.getUpdateTime());
        }
        if (null != house) {
            builder.building(house.getBuilding())
                    .room(house.getRoom());
        }
        builder.ownerName(ownerName == null ? "" : ownerName);
        return builder.build();
    }
}
